<?php

class Currency_model extends CI_Model{
	
	public function __construct(){
		parent::__construct();
	}
	
	function create(){
		$data = array(
					'title' => $this->input->post('title'),
					'code' =>  $this->input->post('code'),
					'symbol_left' => $this->input->post('symbol_left'),
					'symbol_right' => $this->input->post('symbol_right'),
					'value' => $this->input->post('value'),
					'status' => $this->input->post('status'),
					'date_modified' => date ('Y-m-d H:i:s')
				);
		$this->db_front->insert('currency', $data);	
	}
	
	function getAll($page='', $limit=''){
		if(!empty($limit))
		$this->db_front->limit($limit,$page);
		$query = $this->db_front->get('currency');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
	function update($currency_id){
		$data = array(
					'title' => $this->input->post('title'),
					'code' =>  $this->input->post('code'),
					'symbol_left' => $this->input->post('symbol_left'),
					'symbol_right' => $this->input->post('symbol_right'),
					'value' => $this->input->post('value'),
					'status' => $this->input->post('status'),
					'date_modified' => date ('Y-m-d H:i:s')
				);
        $this->db_front->where('currency_id', $currency_id);
        $this->db_front->update('currency', $data);
	}
	
	function select($currency_id){
        return $this->db_front->get_where('currency', array('currency_id'=>$currency_id))->row();
    }
	
	function delete($currency_id){
		$this->db_front->delete('currency', array('currency_id'=>$currency_id));
	}
	
	function getSymbolLeft($currency){
		$query = $this->db_front->query('select symbol_left from currency where currency_id = "'.$currency.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
	function getSymbolRight($currency){
		$query = $this->db_front->query('select symbol_right from currency where currency_id = "'.$currency.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
	function getValue($currency){
		$query = $this->db_front->query('select value from currency where currency_id = "'.$currency.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
	function getCode($currency){
		$query = $this->db_front->query('select code from currency where currency_id = "'.$currency.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
	function getStatus($currency){
		$query = $this->db_front->query('select status from currency where currency_id = "'.$currency.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
}

?>